package controller;

import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import model.BounBookUser;
import util.HibernateUtil;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class RegistrationController extends ActionSupport {
	private static final long serialVersionUID = 1L;

	BounBookUser bounBookUser = new BounBookUser();
	
	public String save() throws Exception {

		Dictionary<String, Object> dictionary = new Hashtable<String, Object>();

		dictionary.put("email", bounBookUser.getEmail());

		List<BounBookUser> userList = HibernateUtil
				.list(
						"from BounBookUser bounBookUser where bounBookUser.email = :email",
						dictionary);

		if (userList.size() >= 1) {
			addActionError("Invalid User!");
			return ERROR;

		} else {
			
			HibernateUtil.insert(bounBookUser);
			
			Map<String, Object> session = ActionContext.getContext().getSession();
			session.put("userType", bounBookUser.getUserType());
			session.put("userId", bounBookUser.getId());
			
			return SUCCESS;
		}
	}

	public BounBookUser getBounBookUser() {
		return bounBookUser;
	}

	public void setBounBookUser(BounBookUser bounBookUser) {
		this.bounBookUser = bounBookUser;
	}
	
	
	
	
	
}
